
package com.ifcar.app.activity.topic;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ifcar.app.adapter.VoteWithTabAdapter;
import com.ifcar.app.util.ThemeSettingsHelper;
import com.ifcar.app.view.VoteGallery;
import com.ifcar.app.activity.R;

public class VoteWithTabFragment extends VoteDataDeal{
	
	private VoteGallery mGallery;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
    	View v = inflater.inflate(R.layout.vote_with_tab_layout, null);
    	mGallery = (VoteGallery) v.findViewById(R.id.vote_layout_grally);
        return v;
    }
    
    @Override
    public void onViewCreatedNR(View view, Bundle savedInstanceState) {
        super.onViewCreatedNR(view, savedInstanceState);
    }
    
    @Override
    public void onTabSelected(boolean first) {
        super.onTabSelected(first);
        setTitle(R.string.main_title_vote);
        if (first) {
            startLoading();
        }
    }
    
    @Override
    public void invalidDataView() {
    	// TODO Auto-generated method stub
    	if(null == mAdapter){
        	mAdapter = new VoteWithTabAdapter(getActivity(), mData);
        }
    	
    	if(null != mGallery){
    		
    		if(null == mGallery.getGallery().getAdapter()){
    			mGallery.setAdapter(mAdapter);
    		}
	    	if (mData.size() > 0) {
	    		if(mGallery.isDoSubmit()){
	    			mGallery.updateDisplay(0);
	    		}
	    		mAdapter.notifyDataSetChanged();
	            mGallery.findViewById(R.id.vote_operator).setVisibility(View.VISIBLE);
	        } else {
	        	mGallery.findViewById(R.id.vote_operator).setVisibility(View.INVISIBLE);
	        }
    	
    	}

    }
    
    @Override
    public void onTabUnSelected() {
        super.onTabUnSelected();
        
//        ListView listView = getListView();
//        if (listView != null) {
//            final int count = listView.getChildCount();
//            for (int i = 0; i < count; i++) {
//                ImageView img = (ImageView) listView.getChildAt(i).findViewById(R.id.img);
//                if (img != null) {
//                    img.setImageDrawable(null);
//                }
//            }
//        }
    }
    
    @Override
    public void onResume() {
    	// TODO Auto-generated method stub
    	super.onResume();
    	if(null != mGallery){
    		mGallery.findViewById(R.id.vote_do).setEnabled(true);
    	}
    	invalidDataView();
    }
    
    @Override
    public void onApplyTheme() {
        super.onApplyTheme();

        ThemeSettingsHelper themeSettingsHelper = getThemeSettingsHelper();
        mGallery.setIndicator(getActivity(), themeSettingsHelper);
        if(null != mAdapter){
        	mAdapter.notifyDataSetChanged();
        }
    }
    
}
